package com.alibaba.nacos.naming.core.v2.client.factory.impl;

import com.alibaba.nacos.naming.core.v2.client.ClientAttributes;
import com.alibaba.nacos.naming.core.v2.client.factory.ClientFactory;
import com.alibaba.nacos.naming.core.v2.client.impl.ConnectionBasedClient;
import org.springframework.stereotype.Component;

@Component
public class ConnectionBasedClientFactory
        implements ClientFactory<ConnectionBasedClient> {

    @Override
    public String getType() {
        return "default";
    }

    @Override
    public ConnectionBasedClient newClient(String clientId,
                                           ClientAttributes clientAttributes) {
        long revision = clientAttributes.getClientAttribute("revision", 0);
        ConnectionBasedClient client = new ConnectionBasedClient(clientId, true, revision);
        client.setAttributes(clientAttributes);
        return client;
    }

    public ConnectionBasedClient newSyncedClient(String clientId,
                                                 ClientAttributes clientAttributes) {
        long revision = clientAttributes.getClientAttribute("revision", 0);
        ConnectionBasedClient client = new ConnectionBasedClient(clientId, false, revision);
        client.setAttributes(clientAttributes);
        return client;
    }
}

